package com.example.imoocmall.common;

import com.example.imoocmall.exception.ImoocMallException;
import com.example.imoocmall.exception.ImoocMallExceptionEnum;
import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.validation.Valid;
import java.util.Set;

/**
 * 专门放常量
 */
@Component
public class Constant {
    public static final String SALT="SJDFLA^%090'$^#%FHsdf";
    public static final String IMOOC_MALL_USER="imooc_mall_user";


    public static String FILE_UPLOAD_DIR;

    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir) {
        FILE_UPLOAD_DIR = fileUploadDir;
    }


    public static String ip;

    @Value("${file.upload.ip}")
    public void setIp(String ip) {
        Constant.ip = ip;
    }

    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc","price asc");
    }

    public interface SaleStatus{
        int NOT_SALE = 0;//没有上架
        int SALE = 1;//上架
    }

    public interface SaleSelect{
        int UN_XCHECKED = 0;//购物车未选中
        int CHECKED = 1;//购物车选中
    }


    public enum OrderStatusEnum{
        CANCELED(0,"用户已取消"),
        NOT_PAID(10,"未付款"),
        PAID(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易完成");
        private String value;
        private int code;

        OrderStatusEnum(int code,String value) {
            this.value = value;
            this.code = code;
        }

        public static OrderStatusEnum codeOf(int code){
            for (OrderStatusEnum orderStatusEnum : values()){
                if (orderStatusEnum.code == code){
                    return orderStatusEnum;
                }
            }
            throw new ImoocMallException(ImoocMallExceptionEnum.NO_ENUM);
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }

}





















